//
//  main.cpp
//  C++01运算符
//
//  Created by GuoRobin on 16/4/14.
//  Copyright © 2016年 Eli. All rights reserved.
//

#include <iostream>
#include <bitset>
using namespace std;


int main(int argc, const char * argv[]) {
    // insert code here...
//    std::cout << "Hello, World!\n";
    
    cout << "Enter a number (0~255):";
    unsigned short InputNum = 0;
    cin >> InputNum;
    
    //cout << "length of unsigned short is %d" << sizeof(unsigned short) << endl;
    
    bitset<8> InputBits (InputNum);
    cout << InputNum << " in binary is " << InputBits << endl;
    
    bitset<8> BitWithNot = (!InputNum);
    bitset<8> BitWithSetter (0x0f);
    
    
    bitset<8> BitWithAnd = (0x0F & InputNum);
    bitset<8> BitWithOr = (0X0F | InputNum);
    bitset<8> BitWithXOR = (0x0f ^ InputNum);
    
    
    cout << BitWithSetter << "!" << InputBits << "=" << BitWithNot << endl;
    cout << BitWithSetter << "&" << InputBits << "=" << BitWithAnd << endl;
    cout << BitWithSetter << "^" << InputBits << "=" << BitWithXOR << endl;
    cout << BitWithSetter << "|" << InputBits << "=" << BitWithOr << endl;
    
    
    return 0;
}
